home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14326 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Square of a floating point number.
  5. Date: Sat, 13 Apr 96 14:25:57 GMT
  6. Organization: none
  7. Message-ID: <829405557snz@genesis.demon.co.uk>
  8. References: <Dpo0Mn.DEo@ireq.hydro.qc.ca>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <Dpo0Mn.DEo@ireq.hydro.qc.ca> pater@ireq.ca "Ryszard Pater" writes:
  15.  
  16. >How could I optimize for a speed the function to compute the square 
  17. >of a floating point number?  I defined a function as follows:
  18. >inline float sqr(float a) {return a*a;}  
  19. >or macro version
  20. >#define sqr(a) ((a)*(a)).
  21. >If You have a better solution give me a feed back, please. 
  22.  
  23. You're not likely to do better than that for a single square operation.
  24. But there again a single square operation isn't going to be speed critical.
  25. Presumably you have an algorithm which performs lots of operation and because
  26. of that is speed critical. To optimise for speed you should consider how
  27. how the algorithm as a whole can be optimised.
  28.  
  29. -- 
  30. -----------------------------------------
  31. Lawrence Kirby | fred@genesis.demon.co.uk
  32. Wilts, England | 70734.126@compuserve.com
  33. -----------------------------------------
  34.